package com.subfg.payment.constant;

import com.subfg.common.entity.excpetion.BusinessExceptionModel;
import com.subfg.common.util.common.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public enum AliTradeStatusEnum {

    SUCCESS("TRADE_SUCCESS"),
    CLOSED("TRADE_CLOSED"),
    FINISHED("TRADE_FINISHED"),
    BUYER("WAIT_BUYER_PAY")
    ;
    private String status;

    AliTradeStatusEnum(String status) {
        this.status = status;
    }

    public String getStatus() {
        return status;
    }

    private static Logger log = LoggerFactory.getLogger(AliTradeStatusEnum.class);

    /**
     * 获取支付状态
     * @param payStatus
     * @return
     */
    public static AliTradeStatusEnum getAliPayStatus(String payStatus) throws BusinessExceptionModel {
        if (!StringUtil.isEmpty(payStatus)) {
            for (AliTradeStatusEnum status : values()) {
                if (payStatus.equals(status.getStatus())) {
                    return status;
                }
            }
        }
        log.info("支付宝支付时错误的验证数据==>>>{}", payStatus);
        throw new BusinessExceptionModel();
    }
}
